home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / libgimp / gimpselection_pdb.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-16  |  15.2 KB  |  618 lines

  1. /* LIBGIMP - The GIMP Library
  2.  * Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
  3.  *
  4.  * gimpselection_pdb.c
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the
  18.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.  * Boston, MA 02111-1307, USA.
  20.  */
  21.  
  22. /* NOTE: This file is autogenerated by pdbgen.pl */
  23.  
  24. #include "gimp.h"
  25.  
  26. /**
  27.  * gimp_selection_bounds:
  28.  * @image_ID: The image.
  29.  * @non_empty: True if there is a selection.
  30.  * @x1: x coordinate of upper left corner of selection bounds.
  31.  * @y1: y coordinate of upper left corner of selection bounds.
  32.  * @x2: x coordinate of lower right corner of selection bounds.
  33.  * @y2: y coordinate of lower right corner of selection bounds.
  34.  *
  35.  * Find the bounding box of the current selection.
  36.  *
  37.  * This procedure returns whether there is a selection for the
  38.  * specified image. If there is one, the upper left and lower right
  39.  * corners of the bounding box are returned. These coordinates are
  40.  * relative to the image. Please note that the pixel specified by the
  41.  * lower righthand coordinate of the bounding box is not part of the
  42.  * selection. The selection ends at the upper left corner of this
  43.  * pixel. This means the width of the selection can be calculated as
  44.  * (x2 - x1), its height as (y2 - y1).
  45.  *
  46.  * Returns: TRUE on success.
  47.  */
  48. gboolean
  49. gimp_selection_bounds (gint32    image_ID,
  50.                gboolean *non_empty,
  51.                gint     *x1,
  52.                gint     *y1,
  53.                gint     *x2,
  54.                gint     *y2)
  55. {
  56.   GimpParam *return_vals;
  57.   gint nreturn_vals;
  58.   gboolean success = TRUE;
  59.  
  60.   return_vals = gimp_run_procedure ("gimp_selection_bounds",
  61.                     &nreturn_vals,
  62.                     GIMP_PDB_IMAGE, image_ID,
  63.                     GIMP_PDB_END);
  64.  
  65.   *non_empty = FALSE;
  66.   *x1 = 0;
  67.   *y1 = 0;
  68.   *x2 = 0;
  69.   *y2 = 0;
  70.  
  71.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  72.  
  73.   if (success)
  74.     {
  75.       *non_empty = return_vals[1].data.d_int32;
  76.       *x1 = return_vals[2].data.d_int32;
  77.       *y1 = return_vals[3].data.d_int32;
  78.       *x2 = return_vals[4].data.d_int32;
  79.       *y2 = return_vals[5].data.d_int32;
  80.     }
  81.  
  82.   gimp_destroy_params (return_vals, nreturn_vals);
  83.  
  84.   return success;
  85. }
  86.  
  87. /**
  88.  * gimp_selection_value:
  89.  * @image_ID: The image.
  90.  * @x: x coordinate of value.
  91.  * @y: y coordinate of value.
  92.  *
  93.  * Find the value of the selection at the specified coordinates.
  94.  *
  95.  * This procedure returns the value of the selection at the specified
  96.  * coordinates. If the coordinates lie out of bounds, 0 is returned.
  97.  *
  98.  * Returns: Value of the selection.
  99.  */
  100. gint
  101. gimp_selection_value (gint32 image_ID,
  102.               gint   x,
  103.               gint   y)
  104. {
  105.   GimpParam *return_vals;
  106.   gint nreturn_vals;
  107.   gint value = 0;
  108.  
  109.   return_vals = gimp_run_procedure ("gimp_selection_value",
  110.                     &nreturn_vals,
  111.                     GIMP_PDB_IMAGE, image_ID,
  112.                     GIMP_PDB_INT32, x,
  113.                     GIMP_PDB_INT32, y,
  114.                     GIMP_PDB_END);
  115.  
  116.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  117.     value = return_vals[1].data.d_int32;
  118.  
  119.   gimp_destroy_params (return_vals, nreturn_vals);
  120.  
  121.   return value;
  122. }
  123.  
  124. /**
  125.  * gimp_selection_is_empty:
  126.  * @image_ID: The image.
  127.  *
  128.  * Determine whether the selection is empty.
  129.  *
  130.  * This procedure returns non-zero if the selection for the specified
  131.  * image is not empty.
  132.  *
  133.  * Returns: Is the selection empty?
  134.  */
  135. gboolean
  136. gimp_selection_is_empty (gint32 image_ID)
  137. {
  138.   GimpParam *return_vals;
  139.   gint nreturn_vals;
  140.   gboolean is_empty = FALSE;
  141.  
  142.   return_vals = gimp_run_procedure ("gimp_selection_is_empty",
  143.                     &nreturn_vals,
  144.                     GIMP_PDB_IMAGE, image_ID,
  145.                     GIMP_PDB_END);
  146.  
  147.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  148.     is_empty = return_vals[1].data.d_int32;
  149.  
  150.   gimp_destroy_params (return_vals, nreturn_vals);
  151.  
  152.   return is_empty;
  153. }
  154.  
  155. /**
  156.  * gimp_selection_translate:
  157.  * @image_ID: The image.
  158.  * @offx: x offset for translation.
  159.  * @offy: y offset for translation.
  160.  *
  161.  * Translate the selection by the specified offsets.
  162.  *
  163.  * This procedure actually translates the selection for the specified
  164.  * image by the specified offsets. Regions that are translated from
  165.  * beyond the bounds of the image are set to empty. Valid regions of
  166.  * the selection which are translated beyond the bounds of the image
  167.  * because of this call are lost.
  168.  *
  169.  * Returns: TRUE on success.
  170.  */
  171. gboolean
  172. gimp_selection_translate (gint32 image_ID,
  173.               gint   offx,
  174.               gint   offy)
  175. {
  176.   GimpParam *return_vals;
  177.   gint nreturn_vals;
  178.   gboolean success = TRUE;
  179.  
  180.   return_vals = gimp_run_procedure ("gimp_selection_translate",
  181.                     &nreturn_vals,
  182.                     GIMP_PDB_IMAGE, image_ID,
  183.                     GIMP_PDB_INT32, offx,
  184.                     GIMP_PDB_INT32, offy,
  185.                     GIMP_PDB_END);
  186.  
  187.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  188.  
  189.   gimp_destroy_params (return_vals, nreturn_vals);
  190.  
  191.   return success;
  192. }
  193.  
  194. /**
  195.  * _gimp_selection_float:
  196.  * @drawable_ID: The drawable from which to float selection.
  197.  * @offx: x offset for translation.
  198.  * @offy: y offset for translation.
  199.  *
  200.  * Float the selection from the specified drawable with initial offsets
  201.  * as specified.
  202.  *
  203.  * This procedure determines the region of the specified drawable that
  204.  * lies beneath the current selection. The region is then cut from the
  205.  * drawable and the resulting data is made into a new layer which is
  206.  * instantiated as a floating selection. The offsets allow initial
  207.  * positioning of the new floating selection.
  208.  *
  209.  * Returns: The floated layer.
  210.  */
  211. gint32
  212. _gimp_selection_float (gint32 drawable_ID,
  213.                gint   offx,
  214.                gint   offy)
  215. {
  216.   GimpParam *return_vals;
  217.   gint nreturn_vals;
  218.   gint32 layer_ID = -1;
  219.  
  220.   return_vals = gimp_run_procedure ("gimp_selection_float",
  221.                     &nreturn_vals,
  222.                     GIMP_PDB_DRAWABLE, drawable_ID,
  223.                     GIMP_PDB_INT32, offx,
  224.                     GIMP_PDB_INT32, offy,
  225.                     GIMP_PDB_END);
  226.  
  227.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  228.     layer_ID = return_vals[1].data.d_layer;
  229.  
  230.   gimp_destroy_params (return_vals, nreturn_vals);
  231.  
  232.   return layer_ID;
  233. }
  234.  
  235. /**
  236.  * gimp_selection_clear:
  237.  * @image_ID: The image.
  238.  *
  239.  * Set the selection to none, clearing all previous content.
  240.  *
  241.  * This procedure sets the selection mask to empty, assigning the value
  242.  * 0 to every pixel in the selection channel.
  243.  *
  244.  * Returns: TRUE on success.
  245.  */
  246. gboolean
  247. gimp_selection_clear (gint32 image_ID)
  248. {
  249.   GimpParam *return_vals;
  250.   gint nreturn_vals;
  251.   gboolean success = TRUE;
  252.  
  253.   return_vals = gimp_run_procedure ("gimp_selection_clear",
  254.                     &nreturn_vals,
  255.                     GIMP_PDB_IMAGE, image_ID,
  256.                     GIMP_PDB_END);
  257.  
  258.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  259.  
  260.   gimp_destroy_params (return_vals, nreturn_vals);
  261.  
  262.   return success;
  263. }
  264.  
  265. /**
  266.  * gimp_selection_invert:
  267.  * @image_ID: The image.
  268.  *
  269.  * Invert the selection mask.
  270.  *
  271.  * This procedure inverts the selection mask. For every pixel in the
  272.  * selection channel, its new value is calculated as (255 - old_value).
  273.  *
  274.  * Returns: TRUE on success.
  275.  */
  276. gboolean
  277. gimp_selection_invert (gint32 image_ID)
  278. {
  279.   GimpParam *return_vals;
  280.   gint nreturn_vals;
  281.   gboolean success = TRUE;
  282.  
  283.   return_vals = gimp_run_procedure ("gimp_selection_invert",
  284.                     &nreturn_vals,
  285.                     GIMP_PDB_IMAGE, image_ID,
  286.                     GIMP_PDB_END);
  287.  
  288.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  289.  
  290.   gimp_destroy_params (return_vals, nreturn_vals);
  291.  
  292.   return success;
  293. }
  294.  
  295. /**
  296.  * gimp_selection_sharpen:
  297.  * @image_ID: The image.
  298.  *
  299.  * Sharpen the selection mask.
  300.  *
  301.  * This procedure sharpens the selection mask. For every pixel in the
  302.  * selection channel, if the value is > 0, the new pixel is assigned a
  303.  * value of 255. This removes any \"anti-aliasing\" that might exist in
  304.  * the selection mask's boundary.
  305.  *
  306.  * Returns: TRUE on success.
  307.  */
  308. gboolean
  309. gimp_selection_sharpen (gint32 image_ID)
  310. {
  311.   GimpParam *return_vals;
  312.   gint nreturn_vals;
  313.   gboolean success = TRUE;
  314.  
  315.   return_vals = gimp_run_procedure ("gimp_selection_sharpen",
  316.                     &nreturn_vals,
  317.                     GIMP_PDB_IMAGE, image_ID,
  318.                     GIMP_PDB_END);
  319.  
  320.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  321.  
  322.   gimp_destroy_params (return_vals, nreturn_vals);
  323.  
  324.   return success;
  325. }
  326.  
  327. /**
  328.  * gimp_selection_all:
  329.  * @image_ID: The image.
  330.  *
  331.  * Select all of the image.
  332.  *
  333.  * This procedure sets the selection mask to completely encompass the
  334.  * image. Every pixel in the selection channel is set to 255.
  335.  *
  336.  * Returns: TRUE on success.
  337.  */
  338. gboolean
  339. gimp_selection_all (gint32 image_ID)
  340. {
  341.   GimpParam *return_vals;
  342.   gint nreturn_vals;
  343.   gboolean success = TRUE;
  344.  
  345.   return_vals = gimp_run_procedure ("gimp_selection_all",
  346.                     &nreturn_vals,
  347.                     GIMP_PDB_IMAGE, image_ID,
  348.                     GIMP_PDB_END);
  349.  
  350.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  351.  
  352.   gimp_destroy_params (return_vals, nreturn_vals);
  353.  
  354.   return success;
  355. }
  356.  
  357. /**
  358.  * gimp_selection_none:
  359.  * @image_ID: The image.
  360.  *
  361.  * Deselect the entire image.
  362.  *
  363.  * This procedure deselects the entire image. Every pixel in the
  364.  * selection channel is set to 0.
  365.  *
  366.  * Returns: TRUE on success.
  367.  */
  368. gboolean
  369. gimp_selection_none (gint32 image_ID)
  370. {
  371.   GimpParam *return_vals;
  372.   gint nreturn_vals;
  373.   gboolean success = TRUE;
  374.  
  375.   return_vals = gimp_run_procedure ("gimp_selection_none",
  376.                     &nreturn_vals,
  377.                     GIMP_PDB_IMAGE, image_ID,
  378.                     GIMP_PDB_END);
  379.  
  380.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  381.  
  382.   gimp_destroy_params (return_vals, nreturn_vals);
  383.  
  384.   return success;
  385. }
  386.  
  387. /**
  388.  * gimp_selection_feather:
  389.  * @image_ID: The image.
  390.  * @radius: Radius of feather (in pixels).
  391.  *
  392.  * Feather the image's selection
  393.  *
  394.  * This procedure feathers the selection. Feathering is implemented
  395.  * using a gaussian blur.
  396.  *
  397.  * Returns: TRUE on success.
  398.  */
  399. gboolean
  400. gimp_selection_feather (gint32  image_ID,
  401.             gdouble radius)
  402. {
  403.   GimpParam *return_vals;
  404.   gint nreturn_vals;
  405.   gboolean success = TRUE;
  406.  
  407.   return_vals = gimp_run_procedure ("gimp_selection_feather",
  408.                     &nreturn_vals,
  409.                     GIMP_PDB_IMAGE, image_ID,
  410.                     GIMP_PDB_FLOAT, radius,
  411.                     GIMP_PDB_END);
  412.  
  413.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  414.  
  415.   gimp_destroy_params (return_vals, nreturn_vals);
  416.  
  417.   return success;
  418. }
  419.  
  420. /**
  421.  * gimp_selection_border:
  422.  * @image_ID: The image.
  423.  * @radius: Radius of border (in pixels).
  424.  *
  425.  * Border the image's selection
  426.  *
  427.  * This procedure borders the selection. Bordering creates a new
  428.  * selection which is defined along the boundary of the previous
  429.  * selection at every point within the specified radius.
  430.  *
  431.  * Returns: TRUE on success.
  432.  */
  433. gboolean
  434. gimp_selection_border (gint32 image_ID,
  435.                gint   radius)
  436. {
  437.   GimpParam *return_vals;
  438.   gint nreturn_vals;
  439.   gboolean success = TRUE;
  440.  
  441.   return_vals = gimp_run_procedure ("gimp_selection_border",
  442.                     &nreturn_vals,
  443.                     GIMP_PDB_IMAGE, image_ID,
  444.                     GIMP_PDB_INT32, radius,
  445.                     GIMP_PDB_END);
  446.  
  447.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  448.  
  449.   gimp_destroy_params (return_vals, nreturn_vals);
  450.  
  451.   return success;
  452. }
  453.  
  454. /**
  455.  * gimp_selection_grow:
  456.  * @image_ID: The image.
  457.  * @steps: Steps of grow (in pixels).
  458.  *
  459.  * Grow the image's selection
  460.  *
  461.  * This procedure grows the selection. Growing involves expanding the
  462.  * boundary in all directions by the specified pixel amount.
  463.  *
  464.  * Returns: TRUE on success.
  465.  */
  466. gboolean
  467. gimp_selection_grow (gint32 image_ID,
  468.              gint   steps)
  469. {
  470.   GimpParam *return_vals;
  471.   gint nreturn_vals;
  472.   gboolean success = TRUE;
  473.  
  474.   return_vals = gimp_run_procedure ("gimp_selection_grow",
  475.                     &nreturn_vals,
  476.                     GIMP_PDB_IMAGE, image_ID,
  477.                     GIMP_PDB_INT32, steps,
  478.                     GIMP_PDB_END);
  479.  
  480.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  481.  
  482.   gimp_destroy_params (return_vals, nreturn_vals);
  483.  
  484.   return success;
  485. }
  486.  
  487. /**
  488.  * gimp_selection_shrink:
  489.  * @image_ID: The image.
  490.  * @radius: Radius of shrink (in pixels).
  491.  *
  492.  * Shrink the image's selection
  493.  *
  494.  * This procedure shrinks the selection. Shrinking invovles trimming
  495.  * the existing selection boundary on all sides by the specified number
  496.  * of pixels.
  497.  *
  498.  * Returns: TRUE on success.
  499.  */
  500. gboolean
  501. gimp_selection_shrink (gint32 image_ID,
  502.                gint   radius)
  503. {
  504.   GimpParam *return_vals;
  505.   gint nreturn_vals;
  506.   gboolean success = TRUE;
  507.  
  508.   return_vals = gimp_run_procedure ("gimp_selection_shrink",
  509.                     &nreturn_vals,
  510.                     GIMP_PDB_IMAGE, image_ID,
  511.                     GIMP_PDB_INT32, radius,
  512.                     GIMP_PDB_END);
  513.  
  514.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  515.  
  516.   gimp_destroy_params (return_vals, nreturn_vals);
  517.  
  518.   return success;
  519. }
  520.  
  521. /**
  522.  * gimp_selection_layer_alpha:
  523.  * @layer_ID: Layer with alpha.
  524.  *
  525.  * Transfer the specified layer's alpha channel to the selection mask.
  526.  *
  527.  * This procedure requires a layer with an alpha channel. The alpha
  528.  * channel information is used to create a selection mask such that for
  529.  * any pixel in the image defined in the specified layer, that layer
  530.  * pixel's alpha value is transferred to the selection mask. If the
  531.  * layer is undefined at a particular image pixel, the associated
  532.  * selection mask value is set to 0.
  533.  *
  534.  * Returns: TRUE on success.
  535.  */
  536. gboolean
  537. gimp_selection_layer_alpha (gint32 layer_ID)
  538. {
  539.   GimpParam *return_vals;
  540.   gint nreturn_vals;
  541.   gboolean success = TRUE;
  542.  
  543.   return_vals = gimp_run_procedure ("gimp_selection_layer_alpha",
  544.                     &nreturn_vals,
  545.                     GIMP_PDB_LAYER, layer_ID,
  546.                     GIMP_PDB_END);
  547.  
  548.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  549.  
  550.   gimp_destroy_params (return_vals, nreturn_vals);
  551.  
  552.   return success;
  553. }
  554.  
  555. /**
  556.  * gimp_selection_load:
  557.  * @channel_ID: The channel.
  558.  *
  559.  * Transfer the specified channel to the selection mask.
  560.  *
  561.  * This procedure loads the specified channel into the selection mask.
  562.  * This essentially involves a copy of the channel's content in to the
  563.  * selection mask. Therefore, the channel must have the same width and
  564.  * height of the image, or an error is returned.
  565.  *
  566.  * Returns: TRUE on success.
  567.  */
  568. gboolean
  569. gimp_selection_load (gint32 channel_ID)
  570. {
  571.   GimpParam *return_vals;
  572.   gint nreturn_vals;
  573.   gboolean success = TRUE;
  574.  
  575.   return_vals = gimp_run_procedure ("gimp_selection_load",
  576.                     &nreturn_vals,
  577.                     GIMP_PDB_CHANNEL, channel_ID,
  578.                     GIMP_PDB_END);
  579.  
  580.   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
  581.  
  582.   gimp_destroy_params (return_vals, nreturn_vals);
  583.  
  584.   return success;
  585. }
  586.  
  587. /**
  588.  * gimp_selection_save:
  589.  * @image_ID: The image.
  590.  *
  591.  * Copy the selection mask to a new channel.
  592.  *
  593.  * This procedure copies the selection mask and stores the content in a
  594.  * new channel. The new channel is automatically inserted into the
  595.  * image's list of channels.
  596.  *
  597.  * Returns: The new channel.
  598.  */
  599. gint32
  600. gimp_selection_save (gint32 image_ID)
  601. {
  602.   GimpParam *return_vals;
  603.   gint nreturn_vals;
  604.   gint32 channel_ID = -1;
  605.  
  606.   return_vals = gimp_run_procedure ("gimp_selection_save",
  607.                     &nreturn_vals,
  608.                     GIMP_PDB_IMAGE, image_ID,
  609.                     GIMP_PDB_END);
  610.  
  611.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  612.     channel_ID = return_vals[1].data.d_channel;
  613.  
  614.   gimp_destroy_params (return_vals, nreturn_vals);
  615.  
  616.   return channel_ID;
  617. }
  618.